﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Hardcodet.Wpf.TaskbarNotification;
using System.Text;
using WpfApplication1.Models;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
using System.IO;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private TaskbarIcon tb;
        private OrdreCollection oc;
        private ObservableCollection<Ordre> ordreItems = new ObservableCollection<Ordre>();
        //private OrdreCollection od;

        public void InitApplication()
        {
            //initialize NotifyIcon
            LoadOrdreData();
            tb = (TaskbarIcon)FindResource("MyNotifyIcon");
            oc = (OrdreCollection)this.FindResource("OrdreList");            
            oc.fillCollectionFromXml("../../Data/Ordrer.xml");

            //od = (OrdreCollection)this.FindResource("Ordrer");
            //od.fillCollectionFromXml("../../Data/Ordrer.xml");
        }

        public ObservableCollection<Ordre> OrdreItems
        {
            get { return this.ordreItems; }
            set { this.ordreItems = value; }
        }

        private void LoadOrdreData()
        {
            fillCollectionFromXml("../../Data/Ordrer.xml");
        }

        private void fillCollectionFromXml(String filepath)
        {
            XmlSerializer xs = new XmlSerializer(typeof(ObservableCollection<Ordre>));
            using (StreamReader rd = new StreamReader(filepath))
            {
                ordreItems = xs.Deserialize(rd) as ObservableCollection<Ordre>;
            }
        }
    }

    class Startup //set the project's startup object to this type
    {
        [STAThread]
        static void Main()
        {
            App app = new App();
            app.InitializeComponent();

            //make sure to call your custom init method before calling Run()
            app.InitApplication();

            app.Run();
        }
    }
}
